package com.suineg.pms.commons.wabacus;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.suineg.pms.commons.AppConfig;
import com.suineg.pms.entity.base.Company;
import com.suineg.pms.service.base.CompanyServcie;
import com.wabacus.config.component.application.report.ReportBean;
import com.wabacus.system.ReportRequest;
import com.wabacus.system.component.application.report.configbean.editablereport.AbsEditActionBean;
import com.wabacus.system.component.application.report.configbean.editablereport.AbsEditableReportEditDataBean;
import com.wabacus.system.component.application.report.configbean.editablereport.EditableReportDeleteDataBean;
import com.wabacus.system.intercept.AbsInterceptorDefaultAdapter;
import com.wabacus.util.Consts;

/**
 * wabacus拦截器  物业公司
 *@author Suine
 */
public class CompanyIntercepter extends AbsInterceptorDefaultAdapter{
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public int doSavePerAction(ReportRequest rrequest, ReportBean rbean,Map<String, String> mRowData, Map<String, String> mParamValues,
			AbsEditActionBean actionbean, AbsEditableReportEditDataBean editbean) {
		// TODO Auto-generated method stub
		if(editbean instanceof EditableReportDeleteDataBean){
			//删除前
			String id = mRowData.get("id");
			CompanyServcie companyServcie = AppConfig.getInstance().getWac().getBean(CompanyServcie.class);
			Company company =  companyServcie.get(Long.valueOf(id));
			if(company == null){
				rrequest.getWResponse().getMessageCollector().alert("无数据", false);
				return AbsInterceptorDefaultAdapter.WX_RETURNVAL_TERMINATE;
			}
			if(company.getCommunityList() != null && company.getCommunityList().size() != 0){
				rrequest.getWResponse().getMessageCollector().warn("此物业公司有下属小区不进行删除操作！", false, Consts.STATECODE_FAILED);
			}
			logger.info(id);
			
		}
		return super.doSavePerAction(rrequest, rbean, mRowData, mParamValues,actionbean, editbean);
	}
}

